package com.example.foobar.dao.service.impl;

import com.example.foobar.entity.DidiPromotion;
import com.example.foobar.mapper.DidiPromotionMapper;
import com.example.foobar.dao.service.DidiPromotionDaoService;
import com.example.foobar.param.DidiPromotionPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 滴滴推广位 服务实现类
 *
 * @author 郑英奔
 * @since 2021-11-16
 */
@Slf4j
@Service
public class DidiPromotionDaoServiceImpl extends BaseServiceImpl<DidiPromotionMapper, DidiPromotion> implements DidiPromotionDaoService {

    @Autowired
    private DidiPromotionMapper didiPromotionMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveDidiPromotion(DidiPromotion didiPromotion) throws Exception {
        return super.save(didiPromotion);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateDidiPromotion(DidiPromotion didiPromotion) throws Exception {
        return super.updateById(didiPromotion);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteDidiPromotion(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<DidiPromotion> getDidiPromotionPageList(DidiPromotionPageParam didiPromotionPageParam) throws Exception {
        Page<DidiPromotion> page = new PageInfo<>(didiPromotionPageParam, OrderItem.desc(getLambdaColumn(DidiPromotion::getCreateTime)));
        LambdaQueryWrapper<DidiPromotion> wrapper = new LambdaQueryWrapper<>();
        IPage<DidiPromotion> iPage = didiPromotionMapper.selectPage(page, wrapper);
        return new Paging<DidiPromotion>(iPage);
    }

}
